/*
 * Filename    : Scene_Alat_Musik.java
 * Projectname : SoiScene
 * Date        : Jan 9, 2013 , 10:47:13 AM 
 * 
 */

package id.pratama.soiscene.scene;

import id.pratama.soiscene.IManageableScene;
import id.pratama.soiscene.MainActivity;
import id.pratama.soiscene.SceneManager;
import id.pratama.soiscene.Utils;
import id.pratama.soiscene.config.IApps_Data;
import id.pratama.soiscene.config.IApps_Define;

import org.andengine.entity.scene.IOnAreaTouchListener;
import org.andengine.entity.scene.ITouchArea;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.scene.background.Background;
import org.andengine.entity.text.Text;
import org.andengine.input.touch.TouchEvent;
import org.andengine.ui.activity.BaseGameActivity;
import org.andengine.util.color.Color;

public class Scene_Alat_Musik extends Scene implements IManageableScene, IApps_Data, IApps_Define, IOnAreaTouchListener
{
	BaseGameActivity			activity;
	Text						txtAngklung, txtGamelan;
	private SceneManager		sm;

	public static final byte	LOAD_ANGKLUNG	= 0;
	public static final byte	LOAD_GAMELAN	= 1;
	public static byte			loadedSound;

	public Scene_Alat_Musik(BaseGameActivity pActivity)
	{
		// TODO Auto-generated constructor stub
		activity = pActivity;
		sm = new SceneManager(activity);
		loadResources();
		applyResources();
		registerUpdateHandler();
	}

	@Override
	public void loadResources()
	{
		// TODO Auto-generated method stub
		setBackground(new Background(Color.WHITE));
		txtAngklung = new Text(0, 0, MainActivity.mFont, "Angklung", activity.getVertexBufferObjectManager());
		txtGamelan = new Text(0, 0, MainActivity.mFont, "Gamelan", activity.getVertexBufferObjectManager());
		this.registerTouchArea(txtAngklung);
		this.registerTouchArea(txtGamelan);

	}

	@Override
	public void applyResources()
	{
		// TODO Auto-generated method stub
		attachChild(txtAngklung);
		attachChild(txtGamelan);
		txtAngklung.setPosition(RES_WIDTH / 2 - txtAngklung.getWidth() / 2, Utils.getRatio(200));
		txtGamelan.setPosition(RES_WIDTH / 2 - txtGamelan.getWidth() / 2, Utils.getRatio(250));

	}

	@Override
	public void registerUpdateHandler()
	{
		// TODO Auto-generated method stub
		this.setOnAreaTouchListener(this);
	}

	@Override
	public void unloadResources()
	{
		// TODO Auto-generated method stub

	}

	@Override
	public boolean onAreaTouched(TouchEvent pSceneTouchEvent, ITouchArea pTouchArea, float pTouchAreaLocalX,
			float pTouchAreaLocalY)
	{
		// TODO Auto-generated method stub
		if (pTouchArea.equals(txtAngklung))
		{
			loadedSound = LOAD_ANGKLUNG;
			sm.setScene(SceneManager.SCENE_PLAYING);

		} else if (pTouchArea.equals(txtGamelan))
		{
			loadedSound = LOAD_GAMELAN;
			sm.setScene(SceneManager.SCENE_PLAYING);
		}
		return false;
	}

}
